package net.lesscoding.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import net.lesscoding.common.Const;
import net.lesscoding.handler.ChatClientChannelInitializer;

/**
 * @author eleven
 * @date 2024/10/31 14:43
 * @apiNote
 */
public class ChatClient {
    public static void main(String[] args) {
        NioEventLoopGroup worker = new NioEventLoopGroup();
        LoggingHandler loggingHandler = new LoggingHandler(LogLevel.DEBUG);
        try {
            Bootstrap bootstrap = new Bootstrap().group(worker)
                    .channel(NioSocketChannel.class)
                    .handler(new ChatClientChannelInitializer(loggingHandler));
            ChannelFuture channelFuture = bootstrap
                    .connect(Const.HOST, Const.PORT);
            channelFuture.sync().channel().closeFuture().sync();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            worker.shutdownGracefully();
        }
    }
}
